package sort;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * ClassName: BobSort
 * Package: sort
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-16
 * Time: 14:10
 */

//冒泡排序
public class BobSort {
    public static void main(String[] args) {

        int[] arr = {6,9,2,9,1};

        int tmp;
        //冒泡排序
        //两层循环 外层-1 内层优化之后-1-i
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]){
                    tmp = arr[j +1];
                    arr[j + 1] = arr[j];
                    arr[j] = tmp;
                }
            }
        }

        System.out.println(Arrays.toString(arr));

    }
}
